/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.mobile.dao;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.cmcc.zysoft.infocollection.model.Device;
import com.starit.common.dao.hibernate.HibernateBaseDaoImpl;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: DeviceDao.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-8-8 上午9:31:42
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Repository
public class MDeviceDao extends HibernateBaseDaoImpl<Device, String> {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	/**
	 * 通过手机号查找到注册的设备号.
	 * @param mobile 手机号
	 * @return String
	 */
	public String getDeviceId(String mobile) {
		String sql = 
				" SELECT dev.device_id " +
				" FROM tb_c_device dev, tb_c_system_user us " +
				" WHERE dev.status = '1' AND dev.employee_id = us.user_id AND us.del_flag = '0' AND us.user_name = ? ";
		List<Map<String, Object>> list = this.jdbcTemplate.queryForList(sql, mobile);
		if(null != list && !list.isEmpty()) {
			return list.get(0).get("device_id").toString();
		} else {
			return "";
		}
	}
	
	/**
	 * 对IMSI号、IMEI号做鉴权.
	 * @param userId 用户ID
	 * @param IMEI IMEI号
	 * @param IMSI IMSI号
	 * @return List<Map<String, Object>>
	 */
	public List<Map<String, Object>> check(String userId, String IMEI, String IMSI) {
		String sql = "SELECT a.* FROM tb_c_device a WHERE a.status = '1' AND a.employee_id = ? AND a.imei = ? AND a.imsi = ?";
		return this.jdbcTemplate.queryForList(sql, userId, IMEI, IMSI);
	}
}